home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12258 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: STRTOL, STRTUL,STRTOD functions
  5. Date: Fri, 29 Mar 96 23:55:09 GMT
  6. Organization: none
  7. Message-ID: <828143709snz@genesis.demon.co.uk>
  8. References: <4ifjao$j5c@news1.h1.usa.pipeline.com> <314ed2d3.110217@news.fred.net> <4ivnod$afn@access4.digex.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4ivnod$afn@access4.digex.net>
  15.            igor@access4.digex.net "Dan White" writes:
  16.  
  17. >>int main(void)
  18. >>{
  19. >>   char *string = "87654321", *endptr;
  20. >>   long lnumber;
  21. >>
  22. >>  /* strtol converts string to long integer  */
  23. >>  /* strtoul converts a string to an unsigned long */
  24. >>  /* strtod converts a string to a double */
  25. >>
  26. >>  /*  *endptr will point to the character that stopped the scan */
  27. >>
  28. >>
  29. >>   lnumber = strtol(string, &endptr, 10);
  30. >>
  31. >>   printf("string = %s  long = %ld\n", string, lnumber);
  32. >>
  33. >>   return 0;
  34. >>}
  35. >>
  36. >>
  37. >>Hope this helps, 
  38. >
  39. >...and what is wrong with using sscanf ?
  40.  
  41. What's wrong with using strtol? It is arguably the more direct and simpler
  42. function to use in this case. atol() is another possibility.
  43.  
  44. -- 
  45. -----------------------------------------
  46. Lawrence Kirby | fred@genesis.demon.co.uk
  47. Wilts, England | 70734.126@compuserve.com
  48. -----------------------------------------
  49.